package com.jt.controller;

import com.jt.service.FileService;
import com.jt.vo.ImageVO;
import com.jt.vo.SySResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.swing.plaf.multi.MultiMenuItemUI;

@RestController
@CrossOrigin
@RequestMapping("/file")
public class FileController {
    @Autowired
    private FileService fileService;
    @PostMapping("/upload")
    /*高级Api SpringMvc  MultipartFile 字节输入流 */
    public SySResult upload(MultipartFile file){
        ImageVO imageVO = fileService.upload(file);
        if(imageVO == null){
            return SySResult.fail();
        }
        return SySResult.success(imageVO);
    }
   @DeleteMapping("/deleteFile")
    public SySResult deleteFile(String virtualPath){
        fileService.deleteFile(virtualPath);
        return SySResult.success();
   }
}
